<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = {
        name: "小乔",
        gender: "男",
        img: "123456",
      };
      //   let sql = `UPDATE heroname set name='${name}',gender='${gender}',img='${img}' WHERE id = ${id}`;
      let sql = "`UPDATE heroname set";
      for (const key in arr) {
        const temSql = `${key} = '${arr[key]}', `;
        sql += temSql;
      }
      sql += "WHERE id = ${10}`";

      const arrey = sql.split("");
      //   获取最后的含有，的下标 //61
      const index = arrey.lastIndexOf(",");
      console.log(index);
      //splice用来删除指定元素位置的数据
      arrey.splice(index, 1);
      sql = arrey.join("");
    </script>
  </body>
</html>
